function OrderCtrl($scope, $http, $cookieStore) {
	Pagination.initialize("/order/findPage", $scope, $http, 15);
	
	$scope.storeCookie = function() {
		$cookieStore.put("formCondition", $scope.formCondition);
	};
	
	$scope.createOrder = function () {
		$scope.storeCookie();
		window.location.href = "/order/add";
	};
	
	$scope.editOrder = function (order) {
		$scope.storeCookie();
		window.location.href = "/order/edit/" + order.id;
	};
	
	$scope.deleteOrder = function (order) {
		Message.confirm("确认", "确认要删除订单“" + order.id + "”？", function () {
			$http.post("/order/delete/" + order.id).success(function (response) {
				if (response.success) {
					$scope.search();
				} else {
					Message.error("错误", response.message || "删除失败！");
				}
			});
		});
	};
	
	$scope.deliverOrder = function (order) {
		Message.confirm("确认", "发货后将把授权清单发送至订单中的客户邮箱，且订单不可再次编辑，确认要为订单“" + order.id + "”发货？", function () {
			$http.post("/order/deliver/" + order.id).success(function (response) {
				if (response.success) {
					$scope.search();
				} else {
					Message.error("错误", response.message || "发货失败！");
				}
			});
		});
	};
	
	$scope.sendEmail = function (order) {
		$http.post("/order/sendEmail/" + order.id).success(function (response) {
			if (response.success) {
				Message.success("信息", "邮件已发送");
			} else {
				Message.error("错误", response.message || "发货失败！");
			}
		});
	};
	
	$scope.init = function() {
		if (QUERY_COOKIE === 'true') {
			$scope.formCondition = $cookieStore.get("formCondition");
		} else {
			$scope.formCondition = {};
		}
		
		$scope.search();
	};
 
	$scope.init();
};

app.controller('OrderCtrl', OrderCtrl);